package com.nimbusung.domain;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.Date;
/**
 * Model to hold a message. 
 * @Author Anton Karlsson
 *
 */
public class Message implements Comparable<Message> {

	private String title;
	private URL link;
	private String description;
	private String pubDate;

	public String getTitle() {
		return title;
	}

	public void setTitle(final String title) {
		this.title = title;
	}

	public URL getLink() {
		return link;
	}

	public void setLink(final String link) {
		try {
			this.link = new URL(link);
		} catch (final MalformedURLException e) {
			throw new RuntimeException(e);
		}
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(final String description) {
		this.description = description;
	}

	public String getPubDate() {
		return this.pubDate;
	}

	public void setPubDate(String date) {
		this.pubDate = date;
	}

	@Override
	public String toString() {
		// omitted for brevity
		return "Title: " + title + " Link: " + link + 
				" Description: " + description;
	}

	@Override
    public boolean equals(final Object o) {
		
		/*
		Date curr = new Date(this.pubDate):
		Date comp = new Date(o(Message))
		if(this.pubDate.)
		
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        final Message that = (Message) o;

        if(title.compareTo(that.title) != 0) return false;
        if(description.compareTo(that.description) != 0) return false;
        if(pubDate.compareTo(that.pubDate) != 0) return false;
        if(!link.equals(that.link)) return false;

        */
        return true;
    }

    @Override
    public int hashCode() {
    	//TODO: Write a better hashCode
        int result;
        result = pubDate != null ? pubDate.hashCode() : 0;
        return result;
    }

	public int compareTo(final Message o) {
		
		Date curr = new Date(this.pubDate);
		Date comp = new Date(o.pubDate);
		//int comparable = comp.compareTo(curr);
		return comp.compareTo(curr);
	}

}
